﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Dal
{
    public class SurtidosDao
    {    
        public static DataSet getSurtidosReport(string cdPais, string ambient)
        {              
          string connection = Credentials.getCredentias(ambient);
          if (connection == null)
          {
              return null;
          }   
       
          SqlCommand cmd = new SqlCommand();
          cmd.Connection = new SqlConnection(connection);
          cmd.CommandType = System.Data.CommandType.StoredProcedure;
          cmd.CommandText = "dbo.dms_Report_ImportAssorted";
          cmd.Parameters.AddWithValue("@cdPais", cdPais);
          cmd.CommandTimeout = 0;

          SqlDataAdapter da = new SqlDataAdapter(cmd);
          DataTable dt = new DataTable("SurtidosDT");

          try
          {
              cmd.Connection.Open();
              da.Fill(dt);
              cmd.Connection.Close();  
          }
          catch (Exception ex)
          {
              Credentials.writeLogFile("getSurtidosReport: " + ex.Message);
              return null;
          }
          DataSet ds = new DataSet("SurtidosDS");
          ds.Tables.Add(dt);
          return ds;       
        }
    }
}
